package mathMethod;

public class ConverToBase7 {

    /**
     * LeetCode T504 七进制数
     * @param args
     */
    public static void main(String[] args) {
        //System.out.println(Integer.toString(100, 7));
        System.out.println(convertToBase7(-7));
    }

    public static String convertToBase7(int num) {
        if (num == 0){
            return "0";
        }
        StringBuilder sb = new StringBuilder();
        int temp = Math.abs(num);
        int a, b;
        while (temp/7 >= 0){
            a = temp / 7;
            b = temp % 7;
            sb.append(b);
            temp = a;
        }
        if (temp != 0){
            sb.append(temp);
        }
        if (num < 0){
            sb.append('-');
        }
        sb.reverse();
        return sb.toString();
    }
}
